﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace MyProject.Tools
{
    public partial class GetVPN : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.lbl_password.Text = GetHtml("http://104.237.156.248/mm.txt");
            }
            catch (Exception ex)
            {
                this.lbl_password.Text = ex.Message;
            }
        }


        public static string GetHtml(string url) //传入要下载的网址
        {
            string str = string.Empty;
            System.Net.WebRequest request = System.Net.WebRequest.Create(url);
            request.Timeout = 10000; //下载超时时间
            request.Headers.Set("Pragma", "no-cache");
            System.Net.WebResponse response = request.GetResponse();
            System.IO.Stream streamReceive = response.GetResponseStream();
            Encoding encoding = Encoding.GetEncoding("gb2312");//utf-8 网页文字编码
            System.IO.StreamReader streamReader = new System.IO.StreamReader(streamReceive, encoding);
            str = streamReader.ReadToEnd();
            streamReader.Close();
            return str;
        }

        protected void btn_getpassword_Click(object sender, EventArgs e)
        {
            try
            {
                this.lbl_password.Text = GetHtml("http://104.237.156.248/mm.txt");
            }
            catch (Exception ex)
            {
                this.lbl_password.Text = ex.Message;
            }
        }
    }
}